package com.pengweiwei.androidzygote.mine;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.fragment.app.FragmentManager;

import com.pengweiwei.androidzygote.R;
import com.pengweiwei.androidzygote.databinding.ActivityCollectionListBinding;
import com.putong35.common.baseactfrag.activity.BaseActivity;


/**
 * 刷列表的模板
 * <p>
 * 主要分为三步：fragment  + adapter(+ layout布局)  + bean
 * <p>
 * 2. adapter要设置 泛型参数（LoginResponce）  e.g extends RecyclerViewBaseAdapter<LoginResponce>
 */
public class CollectionListActivity extends BaseActivity {
    public static final String TAG = CollectionListActivity.class.getSimpleName();
    boolean isEditState = false;
    Button btnRight = null;
    CollectionListFragment listFragment = null;

    public static void start(Context context) {
        Intent starter = new Intent(context, CollectionListActivity.class);
        context.startActivity(starter);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("我的收藏");
        enableBackButton();
        btnRight = getCustomToolbar().addRightButton("管理", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isEditState) {
                    isEditState = true;
                    btnRight.setText("完成");
                    binding.lytBottom.setVisibility(View.VISIBLE);

                } else {
                    isEditState = false;
                    btnRight.setText("管理");
                    binding.lytBottom.setVisibility(View.GONE);
                }
                listFragment.updateState(isEditState);
            }
        });
    }

    ActivityCollectionListBinding binding;
    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = ActivityCollectionListBinding.inflate(getLayoutInflater());
        FragmentManager fragmentManager = getSupportFragmentManager();
        listFragment = (CollectionListFragment) fragmentManager.findFragmentById(R.id.listFrag);
        binding.rbtnChooseAll.setOnCheckedChangeListener((compoundButton, b) -> {
            boolean checkAll = b;
            listFragment.checkAll(checkAll);

        });
        binding.btnDelete.setOnClickListener((v) -> {
            listFragment.clkDelete();
        });
        return binding.getRoot();
    }
}